/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: 2.c
> Author:cww
> Mail: 
> Created Time: 2024年09月23日 星期一 09时45分53秒
***************************************************/
#include <stdio.h>
#include "mysql.h"

int main() {
    MYSQL *connect = connect_mysql();
    if (connect == NULL) {
        printf("Failed to connect to MySQL\n");
        exit(-1);
    }

    Info infor;
    infor.type = 0;
    infor.res = 0;
    infor.temp = 22.5;
    infor.humidity = 45.3;
    infor.O2 = 21.0;
    infor.CO2 = 400.0;
    infor.CH4 = 0.5;
    infor.CO = 0.05;
    strcpy(infor.time, "2024-09-23 10:00:00");
    strcpy(infor.pt, "Sensor A");
    strcpy(infor.principal, "John Doe");
    strcpy(infor.state, "Active");

    Login pro;
    pro.type = 0;
    pro.res = 0;
    strcpy(pro.account, "cww");
    strcpy(pro.password, "123456");

    Instrument data;
    //data.id = 2;
    strcpy(data.name, "Thermometer");
    strcpy(data.contact_way, "Email");
    strcpy(data.Instrument_number, "THM-001");
    strcpy(data.bor_time, "2024-09-23");
    strcpy(data.ret_time, "2024-09-30");
    strcpy(data.state, "Borrowed");

    login(connect, pro);
    info(connect, infor);
    instrument(connect, data);

    // 测试删除和更新功能
    delete_data(connect, "login", "account", "cww");
    update_data(connect, "info", "pt", "sensor", "principal = 'John Doe'");

    mysql_close(connect);
    return 0;
}

